package com.smallrig.mall.template.huawei;

import java.util.HashMap;
import java.util.Map;

public class 寻找最长子串 {

    static char c = 'D';
    static String s = "ABACA123D12345678";

    public static void main(String[] args) {
        System.out.println(solve());
    }

    public static int solve(){
        int max = 0;
        int cnt = 0;
        Map<Character,Integer> map = new HashMap<>();
        int j=0;

        for(int i=j;i<s.length();i++){
            char sc = s.charAt(i);
            if(sc==c){
                cnt = 0;
                map.clear();
                continue;
            }
            map.compute(sc,(k,v)->{
                if(null==v){
                    v = 0;
                }
                return v+1;
            });
            if(map.get(sc)>2){
                cnt = 0;
                i = j++;
                map.clear();
            }else{
                cnt++;
                if(cnt>max){
                    max = cnt;
                }
            }
        }
        return max;
    }

}
